const db = wx.cloud.database()
const getcardsCollection = db.collection('getcards')
const losecardsCollection = db.collection('losecards')
const getStuCollection = db.collection('getStu')
const loseStuCollection = db.collection('loseStu')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    fileList: []
  },

  //学生卡
  stunumber: function (event) {
    console.log(event.detail.value)
    this.setData({
      studentnumber: event.detail.value
    })
  },

  stuname: function (event) {
    console.log(event.detail.value)
    this.setData({
      studentname: event.detail.value
    })
  },

  stulephone: function (event) {
    console.log(event.detail.value)
    this.setData({
      studenttelephone: event.detail.value
    })
  },

  stusubmit: function(event){
    loseStuCollection.add({
      data: {
        studentnumber: this.data.studentnumber,
        studentname: this.data.studentname,
        studenttelephone: this.data.studenttelephone,
        state: false
      }
    }).then(
      wx.showToast({
        title: "添加成功",
        icon: "success",
        duration: 2000
      })
    ),
    wx.requestSubscribeMessage({
        tmplIds: ['MzoHDjYDm_45bJ7t_9XNQGhMqPhv25Co8mAfLGPZgAA'],
        success(res) {
          console.log(res)
        }
      })
  },

  // stusubmit: function (event) {
  //   losecardsCollection.add({
  //     data: {
  //       studentnumber: this.data.studentnumber,
  //       studentname: this.data.studentname,
  //       studenttelephone: this.data.studenttelephone,
  //       category: "学生卡",//false表示还没找到卡，true表示已经找到
  //       state: false
  //     }
  //   }).then(
  //     wx.showToast({
  //       title: '成功',
  //       icon: 'success',
  //       duration: 2000
  //     }),
  //     wx.requestSubscribeMessage({
  //       tmplIds: ['MzoHDjYDm_45bJ7t_9XNQGhMqPhv25Co8mAfLGPZgAA'],
  //       success(res) {
  //         console.log(res)
  //       }
  //     })
  //   )
  // },

  //身份证
  identitynumber: function (event) {
    console.log(event.detail.value)
    this.setData({
      identitynumber: event.detail.value
    })
  },

  identityname: function (event) {
    console.log(event.detail.value)
    this.setData({
      identityname: event.detail.value
    })
  },

  identitytelephone: function (event) {
    console.log(event.detail.value)
    this.setData({
      identitytelephone: event.detail.value
    })
  },

  identitysubmit: function (event) {
    losecardsCollection.add({
      data: {
        identitynumber: this.data.identitynumber,
        identityname: this.data.identityname,
        identitytelephone: this.data.identitytelephone,
        category: "身份证",//false表示还没找到卡，true表示已经找到
        state: false
      }
    }).then(
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000
      }),
      wx.requestSubscribeMessage({
        tmplIds: ['MzoHDjYDm_45bJ7t_9XNQGhMqPhv25Co8mAfLGPZgAA'],
        success(res) {
          console.log(res)
        }
      })
    )
  },

  //银行卡
  banknumber: function (event) {
    console.log(event.detail.value)
    this.setData({
      banknumber: event.detail.value
    })
  },

  banktelephone: function (event) {
    console.log(event.detail.value)
    this.setData({
      bankphone: event.detail.value
    })
  },


  banksubmit: function (event) {
    losecardsCollection.add({
      data: {
        banknumber: this.data.banknumber,
        banktelephone: this.data.banktelephone,
        category: "银行卡",//false表示还没找到卡，true表示已经找到
        state: false
      }
    }).then(
      wx.showToast({
        title: '成功',
        icon: 'success',
        duration: 2000
      }),
      wx.requestSubscribeMessage({
        tmplIds: ['MzoHDjYDm_45bJ7t_9XNQGhMqPhv25Co8mAfLGPZgAA'],
        success(res) {
          console.log(res)
        }
      })
    )
  },
})